package org.sxm.cloud.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.sxm.cloud.dto.product.ProductDTO;
import org.sxm.cloud.entity.product.ProductEntity;
import org.sxm.cloud.service.IProductService;

import java.util.Objects;
/**
* @Description: 产品接口
* @Author: xmSheng
* @Date: 2024/1/22
*/

@RestController
public class ProductController {

    @Autowired
    private IProductService productService;

    /**
     * 查询订单详情
     * @param id
     * @return
     */
    @GetMapping("/product/{id}")
    public ProductEntity getProduct(@PathVariable("id") Integer id) {
        ProductEntity product = productService.getByProductId(id);
        return product;
    }


    /**
     * 扣减产品
     * @param id
     * @param num
     * @return
     */
    @PostMapping("/product/reduse")
    public String reduseProduct(@RequestParam("id") Integer id,@RequestParam Integer num) {
        productService.reduceProduct(id,num);
        return "产品扣减成功";
    }

}
